package com.taobao.dao.impl;

import java.util.List;

import org.apache.http.cookie.Cookie;

import com.taobao.dao.CommonDao;
import com.taobao.dao.PreAlipayDao;
import com.taobao.pojo.Config;
import com.taobao.pojo.HttpContext;

public class PreAlipayDaoImpl extends CommonDao implements PreAlipayDao{

    @Override
    public Object process(HttpContext context) throws Exception {
        String result = null;;
        List<Cookie> cookies = context.getCookieStore().getCookies();
        if (!cookies.isEmpty()) {
            for (int i = 0; i < cookies.size(); i++) {
                if (cookies.get(i).getName().equals("_tb_token_")) {
                    result = cookies.get(i).getValue();
                    break;
                }
            }
        }
        return result;
    }

    @Override
    public String getTBTokenValue() throws Exception {
        return (String) getRequest(Config.alipayUrl);
    }

}
